<?php

/*
 *  Author :  ketu.lai
 *  Email  :  ketu.lai@gmail.com
 *  Date   :  2011-03-19
 *  ID     :  Extensions.php
 */

class Zhishidi_Basic_Block_System_Config_Form_Fieldset_Extensions extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {

    public function render(Varien_Data_Form_Element_Abstract $element) {
        $html = $this->_getHeaderHtml($element);
        $modules = array_keys((array) Mage::getConfig()->getNode('modules')->children());
        sort($modules);

        foreach ($modules as $moduleName) {

            if (strstr($moduleName, 'Zhishidi_') === false) {
                continue;
            }

            $html.= $this->_getFieldHtml($element, $moduleName);
        }
        $html .= $this->_getFooterHtml($element);

        return $html;
    }

    protected function _getFieldRenderer() {
        if (empty($this->_fieldRenderer)) {
            $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
        }
        return $this->_fieldRenderer;
    }

    protected function _getFieldHtml($fieldset, $moduleCode) {
        

        $currentVer = Mage::getConfig()->getModuleConfig($moduleCode)->version;

        $moduleName = substr($moduleCode, strpos($moduleCode, '_') + 1);
        $active = (Mage::getConfig()->getModuleConfig($moduleCode)->is('active', 'true')) ? ' - Enabled' : 'Disabled';
        
        $field = $fieldset->addField($moduleCode, 'label', array(
                    'name' => 'zhishidi_basic_info',
                    'label' => $moduleName,
                    'value' => $currentVer . $active,
                ))->setRenderer($this->_getFieldRenderer());

        return $field->toHtml();
    }

}

?>
